<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
//系统链接获取接口
$return=array();
$tabs=array(
	array('op'=>'system','query'=>'onlyplugin='.$_RQ['onlyplugin'],'title'=>'系统链接'),
);
if($_SESSION['current_plugin']!='core'){	
	$params=array('link'=>1,'type <'=>4,'name'=>$_SESSION['current_plugin']);
	$plugin=pdo_get('core_plugins',$params,'id');
	$link=ROOT_PLUGIN.$_SESSION['current_plugin'].'/manage/actions/link.php';
	if($plugin['id'] && is_file($link)){
		$tabs[]=array('action'=>$_SESSION['current_plugin'].'/link/','query'=>'onlyplugin='.$_RQ['onlyplugin'],'title'=>'本场景页面');
	}
}
$tabs[]=array('op'=>'plugin','query'=>'onlyplugin='.$_RQ['onlyplugin'],'title'=>'插件页面');
$tabs[]=array('op'=>'website','query'=>'onlyplugin='.$_RQ['onlyplugin'].'&fromwxapp='.$_RQ['fromwxapp'],'title'=>'DIY页面');
$tabs[]=array('op'=>'wxapp','query'=>'onlyplugin='.$_RQ['onlyplugin'],'title'=>'小程序地址');
$tabs[]=array('op'=>'article_list','query'=>'onlyplugin='.$_RQ['onlyplugin'],'title'=>'文章选择');
$tabs[]=array('op'=>'product_list','query'=>'onlyplugin='.$_RQ['onlyplugin'],'title'=>'选择商品');
$tabs[]=array('op'=>'diy_url','query'=>'onlyplugin='.$_RQ['onlyplugin'],'title'=>'自定义链');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'system';
if($_RQ['op']=='diy_url'){
	$return['item']=array('url'=>'');
	$return['htmls']=array(
		'type'=>'edit',
		'post'=>'modal_result',
		'result_field'=>'url',
		'edit'=>array(
			array('title'=>'[温馨提示]：<red>小程序环境下H5路径跟小程序路径是通用的</red>；小程序--小程序跳转--链接填写（小程序的短链），<red>可以实现跳转到不同的小程序</red>！','type'=>'tip'),
			array('type'=>'string','name'=>'url','title'=>'链接地址'),
		),
	);
	exi($return);
}
if($_RQ['op']=='system'){
	$return['list']=get_wxapp_pages();
	foreach($return['list'] as $k=>&$item){
		$item['apppath']=wxapp_links($item['url']);
	}
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>'[温馨提示]：<red>小程序环境下H5路径跟小程序路径是通用的</red>；小程序--小程序跳转--链接填写（小程序的短链），<red>可以实现跳转到不同的小程序</red>！','edit'=>false,'delall'=>false,'del_one'=>false,'pagelist'=>false,'list'=>array(
			array('name'=>'title','title'=>'标题','type'=>'string'),
			array('name'=>'url','title'=>'H5路径','type'=>'string'),
			//array('name'=>'apppath','title'=>'小程序路径','type'=>'string'),
		),'action'=>array(
			array('type'=>'modal_result','name'=>'url','title'=>'选取'),
		)),
		'search_one'=>array('name'=>'title','add'=>false),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='plugin'){
	$params=array('link'=>1,'type <'=>4);
	if($_RQ['onlyplugin']){
		$params['name']=$_RQ['onlyplugin'];
	}
	if($_RQ['title']){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$list=pdo_getall('core_plugins',$params,array('name','title'),'','id desc');
	if($list){
		foreach($list as $k=>&$item){
			$item['modal']=array('action'=>'link','plugin'=>$item['name'],'apppath'=>wxapp_links($item['url']));
			$install = check_permission($item['name']);
			if(!$install){
				unset($list[$k]);
			}
		}
	}
	$return['list']=$list;
	$htmls=array(
			'type'=>'list',
			'tabs'=>$tabs,
			'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_one'=>false,'list'=>array(
				array('name'=>'name','title'=>'插件标识','type'=>'string'),
				array('name'=>'title','title'=>'插件名称','type'=>'string'),
			),'action'=>array(
				array('type'=>'modal','name'=>'modal','title'=>'进入'),
			)),
			'search_one'=>array('name'=>'title','add'=>false),
		);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='wxapp'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'appid <>'=>'');
	if($_RQ['title']){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$list=pdo_getall('core_account_wxapp',$params,array('id','appid','title'),'','id desc');
	if($list){
		foreach($list as &$item){
			$item['wxappurl']=custom_url('core/home.scheme//type=wxapp&id='.$item['id'],true);
			$item['wxapppath']='core/home.scheme//appid='.$item['appid'];
			$item['url']='core/home.scheme//appid='.$item['appid'].'&type=wxapp&id='.$item['id'];
		}
	}
	$return['list']=$list;
	$htmls=array(
			'type'=>'list',
			'tabs'=>$tabs,
			'list'=>array('data'=>'list','tip'=>'只显示已经设置了appid的小程序（最新的小程序包才支持互跳）！','edit'=>false,'delall'=>false,'del_one'=>false,'list'=>array(
				array('name'=>'title','title'=>'小程序名称','type'=>'string'),
				array('name'=>'appid','title'=>'Appid','type'=>'string'),
				//array('type'=>'string','title'=>'小程序H5网址','name'=>'wxappurl'),
				array('type'=>'string','title'=>'小程序跳转地址','name'=>'wxapppath'),
			),'action'=>array(
				array('type'=>'modal_result','name'=>'url','title'=>'选取'),
			)),
			'search_one'=>array('name'=>'title','add'=>false),
		);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='article'){
	$pindex=max(1,intval($_RQ['page']));
	$psize=10;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['id']){
		$params['fenlei']=$_RQ['id'];
		$return['params']['fenlei']=$_RQ['id'];
	}
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$total=0;
	$fields=array('id','title','createtime');
	$list=pdo_getslice('core_account_article',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['createtime']=date('y/m/d H:i:s',$item['createtime']);			
			$item['url']='core/article.list/detail/id='.$item['id'];
			$item['apppath']=wxapp_links($item['url']);

		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_one'=>false,'list'=>array(
			array('name'=>'title','title'=>'标题','type'=>'string'),
			array('name'=>'url','title'=>'H5路径','type'=>'string'),
			//array('name'=>'apppath','title'=>'小程序路径','type'=>'string'),
			//array('name'=>'createtime','title'=>'创建时间','type'=>'string'),
		),'action'=>array(
			array('type'=>'modal_result','name'=>'url','title'=>'选取'),
		)),
		'search_one'=>array('name'=>'title','add'=>false),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='article_list'){
	$pindex=max(1,intval($_RQ['page']));
	$psize=10;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$total=0;
	$fields=array('id','title','createtime');
	$list=pdo_getslice('core_account_article_fenlei',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['createtime']=date('y/m/d H:i:s',$item['createtime']);
			$item['url']='core/article.list//group_id='.$item['id'];
			$item['apppath']=wxapp_links($item['url']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_one'=>false,'list'=>array(
			array('name'=>'title','title'=>'标题','type'=>'string'),
			array('name'=>'url','title'=>'H5路径','type'=>'string'),
			//array('name'=>'apppath','title'=>'小程序路径','type'=>'string'),
			//array('name'=>'createtime','title'=>'创建时间','type'=>'string'),
			array('type'=>'modal','action'=>'core/tools.link/article/','query'=>'onlyplugin='.$_RQ['onlyplugin'],'title'=>'旗下文章'),
		),'action'=>array(
			array('type'=>'modal_result','name'=>'url','title'=>'选取链接'),
		)),
		'search_one'=>array('name'=>'title','add'=>false),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='product'){
	$pindex=max(1,intval($_RQ['page']));
	$psize=10;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	if($_RQ['id']){
		$params['pcate']=$_RQ['id'];
		$return['params']['pcate']=$_RQ['id'];
	}
	$total=0;
	$fields=array('id','title','price','image');
	$list=pdo_getslice('jy_weishop_goods',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['createtime']=date('y/m/d H:i:s',$item['createtime']);
			$item['url']='jy_weishop/goods.detail//id='.$item['id'];
			$item['apppath']=wxapp_links($item['url']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_one'=>false,'list'=>array(
			array('type'=>'img_string','title'=>'商品信息_Goods title','img'=>'image',
			'data'=>array(
				array('title'=>'标题：','name'=>'title'),
				array('title'=>'价格：','name'=>'price')
				)
			),
			array('name'=>'url','title'=>'H5路径','type'=>'string'),
			//array('name'=>'apppath','title'=>'小程序路径','type'=>'string'),
		),'action'=>array(
			array('type'=>'modal_result','name'=>'url','title'=>'选取'),
		)),
		'search_one'=>array('name'=>'title','add'=>false),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='product_list'){
	$pindex=max(1,intval($_RQ['page']));
	$psize=10;
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>0,'parentid'=>0,'onepluginname'=>'');
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$total=0;
	$fields=array('id','title','image');
	$list=pdo_getslice('jy_weishop_goods_group',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			if($item['parentid']==0){
				$item['url']='jy_weishop/goods.index//pid='.$item['id'];
			}else{
				$item['url']='jy_weishop/goods.index//cid='.$item['id'];
			}
			$item['apppath']=wxapp_links($item['url']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_one'=>false,'list'=>array(
			array('type'=>'img_string','title'=>'分类信息_Group title','img'=>'image',
			'data'=>array(
				array('title'=>'ID：','name'=>'id'),
				array('title'=>'标题：','name'=>'title')
				)
			),
			array('name'=>'url','title'=>'H5路径','type'=>'string'),
			//array('name'=>'apppath','title'=>'小程序路径','type'=>'string'),
			array('type'=>'modal','action'=>'core/tools.link/product/','query'=>'onlyplugin='.$_RQ['onlyplugin'],'title'=>'旗下商品'),
		),'action'=>array(
			array('type'=>'modal_result','name'=>'url','title'=>'选取'),
		)),
		'search_one'=>array('name'=>'title','add'=>false),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='website'){
	$pindex=max(1,intval($_RQ['page']));
	$psize=10;
	$params=array('uniacid'=>$_SESSION['uniacid'],'webid'=>0,'pctype <='=>1);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$total=0;
	$fields=array('id','title','createtime');
	$list=pdo_getslice('core_mobile_web',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['createtime']=date('y/m/d H:i:s',$item['createtime']);
			$item['url']='core/welcome//id='.$item['id'];
			$item['apppath']=wxapp_links($item['url']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_one'=>false,'tip'=>'<red>如果本微官网要生成小程序，请勿选择本DIY页面作为链接！</red>这里只显示DIY页面（系统页面，头部，底部等类型页面不显示）！','list'=>array(
			array('name'=>'title','title'=>'标题','type'=>'string'),
			array('name'=>'url','title'=>'H5路径','type'=>'string'),
			//array('name'=>'apppath','title'=>'小程序路径','type'=>'string'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'string'),
		),'action'=>array(
			array('type'=>'modal_result','name'=>'url','title'=>'选取'),
		)),
		'search_one'=>array('name'=>'title','add'=>false),
	);
	$htmls2=array(
		'type'=>'edit',
		'tabs'=>$tabs,
		'edit'=>array(
				array('name'=>'title','title'=>'[温馨提示]：属于DIY小程序，不能选择其他微官网的DIY页面！','type'=>'tip'),
		),
	);
	if($_RQ['fromwxapp']){
		$return['htmls']=$htmls2;
	}else{
		$return['htmls']=$htmls;
	}
	
	exi($return);
}
?>

